lundi 11 avril 2022

Field data types fingerprints for "validateUpdateListItem"

Field data types fingerprints for "validateUpdateListItem"

With "validateUpdateListItem" all major field data types update is supported, yet it can be difficult sometimes to find the correct format. So as a bonus section: 


.validateUpdateListItem([
  // Text field (single line and note)
  { FieldName: 'TextField', FieldValue: '123' },
  // Number field
  { FieldName: 'NumberField', FieldValue: '123'  },
  // Yes/No field
  { FieldName: 'YesNoField', FieldValue: '1' /* Yes, No, 1, 2 */ },
  // Person or group, single and multiple
  { FieldName: 'PersonField', FieldValue: JSON.stringify([{ Key: LoginName }]) },
  // Dates should be in in the following formats
  { FieldName: 'DateTimeField', FieldValue: '6/23/2018 10:15 PM' },
  { FieldName: 'DateField', FieldValue: '6/23/2018' },
  // Choice field (single and multi-valued)
  { FieldName: 'ChoiceField', FieldValue: 'Choice 1' },
  { FieldName: 'MultiChoiceField', FieldValue: 'Choice 1;#Choice 2' },
  // Hyperlink or picture (after URL a description can go after ', ' delimeter)
  { FieldName: 'HyperlinkField', FieldValue: 'https://arvosys.com, ARVO Systems' },
  // Lookups fields (single and multi-valued)
  { FieldName: 'LookupField', FieldValue: '2' /* Item ID as string */ },
  { FieldName: 'MutliLookupField', FieldValue: [3, 4, 5].map(id => `${id};#`).join(';#') },
  // Mamnaged metadata fields (single and multi-valued)
  { FieldName: 'SingleMMDField', FieldValue: 'Department 2|220a3627-4cd3-453d-ac54-34e71483bb8a;' },
  { FieldName: 'MultiMMDField', FieldValue: 'Department 2|220a3627-4cd3-453d-ac54-34e71483bb8a;Department 3|700a1bc3-3ef6-41ba-8a10-d3054f58db4b;' }
]);

Happy coding!

dimanche 10 avril 2022

[SAP] Génération des documents via la transaction SFP

 la génération des rapports au niveau de SAP de Fait via la transaction SFP

elle se base sur deux notions:

1- les interfaces : c'est la ou on va créer les types d'entrées , et ou on va intier le code 

2- les formulaires : c'est la ou va définir les templates , un formulaire doit faire appel à une interface , plusieurs formulaires peuvent faire appel à la même interface

Create an interface:

/wp-content/uploads/2016/01/pic_865709.jpg

Add a few import parms to the interface:

/wp-content/uploads/2016/01/pic_865709.jpg

Create a form which will use the interface and drag the interface import fields over to the Context of the form:

/wp-content/uploads/2016/01/pic_865709.jpg


Change layout Type to “ZCI Layout”


/wp-content/uploads/2016/01/pic_865709.jpg

Start Adobe LiveCycle and choose the “Layout” tab page and then “Utilities” -> “Insert Web Dynpro Script”.


Add three “ISR Text Edit” fields to the layout:


    From the Data View, drag over and bind each input field from the interface to one of the input fields on the layout of the form.


/wp-content/uploads/2016/01/pic_865709.jpg


Activate the form.


Abap Code for Report Program to call the form:

Code to call from a standard abap report:

report ytest_sfp_form.

start-of-selection.

data :fp_outputparams   type sfpoutputparams.

fp_outputparamsnodialog = ‘X’.
fp_outputparams
preview  = ‘X’.
*  fp_docparams-FILLABLE    = ‘N’.
fp_outputparams
device   = ‘PRINTER’.
fp_outputparams
connection = ‘ADS’.
fp_outputparams
bumode = ‘-‘.
fp_outputparams
dest = ‘LPDF’.
fp_outputparams
dataset = ‘PBFORM’.
fp_outputparams
pdltype= ‘pdf’.
fp_outputparams
xdcname = ‘acrobat6.xdc’.

call function ‘FP_JOB_OPEN’
changing
ie_outputparams
= fp_outputparams
exceptions
cancel         
= 1
usage_error    
= 2
system_error   
= 3
internal_error 
= 4
others          = 5.
if sysubrc <> 0.
message id symsgid type symsgty number symsgno
with symsgv1 symsgv2 symsgv3 symsgv4.
endif.

data: lv_char50_1 type char50, lv_char50_2 type char50, lv_char50_3 type char50.

lv_char50_1 = ‘Test Parm 1’.
lv_char50_2
= ‘Test Parm 2’.
lv_char50_3
= ‘Test Parm 3’.

call function ‘/1BCDWB/SM00000205’
exporting
lv_char50_1
= lv_char50_1
lv_char50_2
= lv_char50_2
lv_char50_3
= lv_char50_3.

if sysubrc <> 0.
*   Implement suitable error handling here
endif.

call function ‘FP_JOB_CLOSE’
exceptions
usage_error   
= 1
system_error  
= 2
internal_error
= 3
others         = 4.
if sysubrc <> 0.
*   Implement suitable error handling here
endif.

lundi 8 janvier 2018

Generate QrCode in RDLC with Qrcode.net and MemoryStream without saving it

  Je vous propose un code pour générer le QrCode dans un rapport RDLC sans avoir à le stocker dans un endroit précis

Pour Cela on utilise l'outil  QrCode.net , on insére le code suivant;
         ReportDataSource rds = new ReportDataSource();
                rds = new ReportDataSource("MyDataSet", list);
                              
                Bitmap BitmapCaptcha =  GenerateQrCode("HelloWord", Brushes.Black, Brushes.White, 200);
                MemoryStream ms = new MemoryStream();
                BitmapCaptcha.Save(ms, ImageFormat.Gif);
                var base64Data = Convert.ToBase64String(ms.ToArray());
                string QR_IMG = base64Data;
                ReportParameter parameter = new ReportParameter("QR_IMG", QR_IMG, true);

                ReportViewer1.LocalReport.EnableExternalImages = true;
                ReportViewer1.LocalReport.ReportPath = Page.Server.MapPath("~/rdlc/Fiche.rdlc");
                ReportViewer1.LocalReport.DataSources.Clear();
                ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { parameter });
                ReportViewer1.LocalReport.DataSources.Add(rds);

  public static Bitmap GenerateQrCode(string url, Brush darkColor, Brush lightColor, int size)
        {
            var encoder = new QrEncoder(ErrorCorrectionLevel.L);
            var code = encoder.Encode(url);
            var renderer = new GraphicsRenderer(new FixedCodeSize(size, QuietZoneModules.Zero), darkColor, lightColor);
            using (var ms = new MemoryStream())
            {
                renderer.WriteToStream(code.Matrix, ImageFormat.Png, ms);
                return new Bitmap(ms);
            }
        }


Au niveau du RDLC :

on insére une image
 on met dans le mimetype : image/gif
dans Source:  Database
dans value: = System.Convert.FromBase64String(Parameters!QR_IMG.Value)


pour plus de détails laissez un commentaire.




mardi 6 décembre 2016

Top 10 Tricky Java interview questions and Answers

10 Tricky Java interview question - Answered

Here is my list of 10 tricky Java interview questions, Though I have prepared and shared lot of difficult core Java interview question and answers, But I have chosen them as Top 10 tricky questions because you can not guess answers of this tricky Java questions easily, you need some subtle details of Java programming language to answer these questions.
Question: What does the following Java program print?
public class Test {
    public static void main(String[] args) {
        System.out.println(Math.min(Double.MIN_VALUE, 0.0d));
    }
}
Answer: This question is tricky because unlike the Integer, where MIN_VALUE is negative, both the MAX_VALUE and MIN_VALUE of the Double class are positive numbers. The Double.MIN_VALUE is 2^(-1074), a double constant whose magnitude is the least among all double values. So unlike the obvious answer, this program will print 0.0 because Double.MIN_VALUE is greater than 0. I have asked this question to Java developer having experience up to 3 to 5 years and surprisingly almost 70% candidate got it wrong.

What will happen if you put return statement or System.exit () on try or catch block? Will finally block execute?
This is a very popular tricky Java question and it's tricky because many programmers think that no matter what, but the finally block will always execute. This question challenge that concept by putting a return statement in the try or catch block or calling System.exit() from try or catch block. Answer of this tricky question in Java is that finally block will execute even if you put a return statement in the try block or catch block but finally block won't run if you call System.exit() from try or catch block.


Question: Can you override a private or static method in Java?
Another popular Java tricky question, As I said method overriding is a good topic to ask trick questions in Java. Anyway, you can not override a private or static method in Java, if you create a similar method with same return type and same method arguments in child class then it will hide the superclass method, this is known as method hiding.
Similarly, you cannot override a private method in sub class because it's not accessible there, what you do is create another private method with the same name in the child class.



Question: What do the expression 1.0 / 0.0 will return? will it throw Exception? any compile time error?
Answer: This is another tricky question from Double class. Though Java developer knows about the double primitive type and Double class, while doing floating point arithmetic they don't pay enough attention to Double.INFINITY, NaN, and -0.0 and other rules that govern the arithmetic calculations involving them. The simple answer to this question is that it will not throw ArithmeticExcpetion and return Double.INFINITY.

Also, note that the comparison x == Double.NaN always evaluates to false, even if x itself is a NaN. To test if x is a NaN, one should use the method call Double.isNaN(x) to check if given number is NaN or not. If you know SQL, this is very close to NULL there. 
Does Java support multiple inheritances?
This is the trickiest question in Java if C++ can support direct multiple inheritances than why not Java is the argument Interviewer often give. Answer of this question is much more subtle then it looks like, because Java does support multiple inheritances of Type by allowing an interface to extend other interfaces, what Java doesn't support is multiple inheritances of implementation. This distinction also gets blur because of default method of Java 8, which now provides Java, multiple inheritances of behavior as well.


What will happen if we put a key object in a HashMap which is already there?
This tricky Java question is part of another frequently asked question, How HashMap works in Java. HashMap is also a popular topic to create confusing and tricky question in Java. Answer of this question is if you put the same key again then it will replace the old mapping because HashMap doesn't allow duplicate keys. The Same key will result in the same hashcode and will end up at the same position in the bucket.
 Each bucket contains a linked list of Map.Entry object, which contains both Key and Value. Now Java will take the Key object from each entry and compare with this new key using equals() method, if that return true then value object in that entry will be replaced by new value.



Question: What does the following Java program print?
public class Test {
    public static void main(String[] args) throws Exception {
        char[] chars = new char[] {'\u0097'};
        String str = new String(chars);
        byte[] bytes = str.getBytes();
        System.out.println(Arrays.toString(bytes));
    }
}

Answer: The trickiness of this question lies on character encoding and how String to byte array conversion works. In this program, we are first creating a String from a character array, which just has one character '\u0097', after that we are getting the byte array from that String and printing that byte. Since \u0097 is within the 8-bit range of byte primitive type, it is reasonable to guess that the str.getBytes() call will return a byte array that contains one element with a value of -105 ((byte) 0x97).

However, that's not what the program prints and that's why this question is tricky. As a matter of fact, the output of the program is operating system and locale dependent. On a Windows XP with the US locale, the above program prints [63], if you run this program on Linux or Solaris, you will get different values.

To answer this question correctly, you need to know about how Unicode characters are represented in Java char values and in Java strings, and what role character encoding plays in String.getBytes().

In simple word, to convert a string to a byte array, Java iterate through all the characters that the string represents and turn each one into a number of bytes and finally put the bytes together. The rule that maps each Unicode character into a byte array is called a character encoding. So It's possible that if same character encoding is not used during both encoding and decoding then retrieved value may not be correct. When we call str.getBytes() without specifying a character encoding scheme, the JVM uses the default character encoding of the platform to do the job.

The default encoding scheme is operating system and locale dependent. On Linux, it is UTF-8 and on Windows with a US locale, the default encoding is Cp1252. This explains the output we get from running this program on Windows machines with a US locale. No matter which character encoding scheme is used, Java will always translate Unicode characters not recognized by the encoding to 63, which represents the character U+003F (the question mark, ?) in all encodings.


If a method throws NullPointerException in the superclass, can we override it with a method which throws RuntimeException?
One more tricky Java questions from the overloading and overriding concept. The answer is you can very well throw superclass of RuntimeException in overridden method, but you can not do same if its checked Exception.


What is the issue with following implementation of compareTo() method in Java
public int compareTo(Object o){
   Employee emp = (Employee) o;
   return this.id - e.id;
}
where an id is an integer number.
Well, three is nothing wrong in this Java question until you guarantee that id is always positive. This Java question becomes tricky when you can't guarantee that id is positive or negative. the tricky part is, If id becomes negative than subtraction may overflow and produce an incorrect result.



How do you ensure that N thread can access N resources without deadlock?
If you are not well versed in writing multi-threading code then this is a real tricky question for you. This Java question can be tricky even for the experienced and senior programmer, who are not really exposed to deadlock and race conditions. The key point here is ordering, if you acquire resources in a particular order and release resources in the reverse order you can prevent deadlock.


Question: Consider the following Java code snippet, which is initializing two variables and both are not volatile, and two threads T1 and T2 are modifying these values as following, both are not synchronized
int x = 0;
boolean bExit = false;

Thread 1 (not synchronized)
x = 1; 
bExit = true;

Thread 2 (not synchronized)
if (bExit == true) 
System.out.println("x=" + x);
Now tell us, is it possible for Thread 2 to print “x=0”?

Answer: It's impossible for a list of tricky Java questions to not contain anything from multi-threading. This is the simplest one I can get. Answer of this question is Yes, It's possible that thread T2 may print x=0.Why? because without any instruction to compiler e.g. synchronized or volatile, bExit=true might come before x=1 in compiler reordering. Also, x=1 might not become visible in Thread 2, so Thread 2 will load x=0. Now, how do you fix it?

 When I asked this question to a couple of programmers they answer differently, one suggests to make both threads synchronized on a common mutex, another one said make both variable volatile. Both are correct, as it will prevent reordering and guarantee visibility.

But the best answer is you just need to make bExit as volatile, then Thread 2 can only print “x=1”. x does not need to be volatile because x cannot be reordered to come after bExit=true when bExit is volatile.

What is difference between CyclicBarrier and CountDownLatch in Java
Relatively newer Java tricky question, only been introduced from Java 5. The main difference between both of them is that you can reuse CyclicBarrier even if Barrier is broken, but you can not reuse CountDownLatch in Java.

What is the difference between StringBuffer and StringBuilder in Java?
Classic Java questions which some people think tricky and some consider very easy. StringBuilder in Java was introduced in JDK 1.5 and the only difference between both of them is that StringBuffer methods e.g. length(), capacity() or append() are synchronized while corresponding methods in StringBuilder are not synchronized.

Because of this fundamental difference, concatenation of String using StringBuilder is faster than StringBuffer. Actually, it's considered the bad practice to use StringBuffer anymore, because, in almost 99% scenario, you perform string concatenation on the same thread.


Can you access a non-static variable in the static context?
Another tricky Java question from Java fundamentals. No, you can not access a non-static variable from the static context in Java. If you try, it will give compile time error. This is actually a common problem beginner in Java face when they try to access instance variable inside the main method. Because main is static in Java, and instance variables are non-static, you can not access instance variable inside main. See, why you can not access a non-static variable from static method to learn more about this tricky Java questions.

Questions for practice
  1. When doesn't Singleton remain Singleton in Java?
  2. is it possible to load a class by two ClassLoader?
  3. is it possible for equals() to return false, even if contents of two Objects are same?
  4. Why compareTo() should be consistent to equals() method in Java?
  5. When do Double and BigDecimal give different answers for equals() and compareTo() == 0. 
  6. How does "has before" apply to volatile work?
  7. Why is 0.1 * 3 != 0.3,
  8. Why is (Integer) 1 == (Integer) 1 but (Integer) 222 != (Integer) 222 and which command arguments change this.
  9. What happens when an exception is thrown by a Thread?
  10. Difference between notify() and notifyAll() call?
  11. Difference between System.exit() and System.halt() method?
  12. Does following code legal in Java? is it an example of method overloading or overriding?
  13. public String getDescription(Object obj){
       return obj.toString;
    }
    public String getDescription(String obj){
       return obj;
    }
    and
    public void getDescription(String obj){
       return obj;
    }


This was my list of Some of the most common tricky questions in Java. It's not a bad idea to prepare tricky Java question before appearing for any core Java or J2EE interview. One or two open-ended or tricky question is quite common in Java interviews.