2010 Nov 30 9:53 AM
Hi,
I have made a program for merge of data in a table. However, this is conditioned and I have 3 IF statements as seen below:
IF wa2_grmres-valid_from_date NE v_next_date.
IF wa2_grmres-cpmap_type NE v_next_mapt.
IF wa2_grmres-grm_int_cpgrp_id NS v_next_grmcp.
The 2 first works fine but the third is not working as it does not execute the code when it is true.
The wa2_grmres-grm_int_cpgrp_id field is defined as CHAR 12. So is the variable v_next_grmcp.
When debugging the values for the 2 fields are correctly different. However, the if statement is ignored. Am I missing something here ?
2010 Nov 30 12:17 PM
Hi,
I have made a program for merge of data in a table. However, this is conditioned and I have 3 IF statements as seen below:
IF wa2_grmres-valid_from_date NE v_next_date.
IF wa2_grmres-cpmap_type NE v_next_mapt.
IF wa2_grmres-grm_int_cpgrp_id NS v_next_grmcp.
The 2 first works fine but the third is not working as it does not execute the code when it is true.
The wa2_grmres-grm_int_cpgrp_id field is defined as CHAR 12. So is the variable v_next_grmcp.
When debugging the values for the 2 fields are correctly different. However, the if statement is ignored. Am I missing something here ?
2010 Nov 30 9:57 AM
Hi,
For the last IF try this
IF wa2_grmres-grm_int_cpgrp_id NE v_next_grmcp.
Regards,
Nagaraj
2010 Nov 30 10:03 AM
HI,
Is the control coming to the if condition ?
Why dont you try with
IF wa2_grmres-grm_int_cpgrp_id NE v_next_grmcp.
Regards,
Madhukar Shetty
2010 Nov 30 10:10 AM
Hi,
I did try NE as condition without luck. I come to the IF block of statements and then it goes on to my endloop and proceeds with the next record as nothing had happended. It should actually enter the IF block and execute as I have 2 different values in the fields.
2010 Nov 30 10:13 AM
Hi,
Use condense statement before the IF statement and see.
condense : wa2_grmres-grm_int_cpgrp_id ,
v_next_grmcp.
IF wa2_grmres-grm_int_cpgrp_id NE v_next_grmcp
Regards,
Nagaraj
2010 Nov 30 10:14 AM
HI,
Did you check in debug what are the value in the two variable ? i.e wa2_grmres-grm_int_cpgrp_id v_next_grmcp ?
Regards,
Madhukar Shetty
2010 Nov 30 10:16 AM
Hi,
Check the value of both in debugging mode when the if condition is reached.
If the leading zeros is the problem, then you can use pack/unpack accordingly before the condition to make sure the value are checked properly.
2010 Nov 30 10:19 AM
Hi,
The values to be compared are different; that is seen in the debugger.
I will try the condense and come back. Thanks.
2010 Nov 30 11:09 AM
2010 Nov 30 11:12 AM
Hi,
Can you please paste the values for both the variables which you are getting in debug mode.
Regards,
Nagaraj
2010 Nov 30 11:16 AM
Yes, here they are:
WA2_GRMRES-GRM_INT_CPGRP_ID Value = B00018687074
V_NEXT_GRMCP Value = B00000191033
2010 Nov 30 10:18 AM
Did you read the F1 documentation on NS: [http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb3516358411d1829f0000e829fbfe/content.htm] ?
There is an example which explains how the string operators behave. Maybe that should throw some light
2010 Nov 30 11:52 AM
Hi
Check your declarationns once again.
As, the test program does end-up giving out 'Not equal'.
DATA: v_c1 TYPE char12,
v_c2 TYPE char12.
START-OF-SELECTION.
v_c1 = 'B00018687074'.
v_c2 = 'B00000191033'.
IF v_c1 NE v_c2.
WRITE:/ 'Not equal', v_c1, v_c2.
ELSE.
WRITE:/ 'equal', v_c1, v_c2.
ENDIF.
Regards
Raj
2010 Nov 30 12:10 PM
2010 Nov 30 12:24 PM
Hi Peter,
Are you sure that "IF wa2_grmres-cpmap_type NE v_next_mapt." is true, that is the values of the variables in the condition are different?
Regards,
Chen
2010 Nov 30 12:28 PM
zc1crd_grm_grmap_t is a table type of the db table,
zc1_int_cparty_id is a data element of char 12.
I have debugged and the 2 values were different before entering the IF-clause.
Peter
2010 Nov 30 12:17 PM
2010 Nov 30 12:20 PM
Here it is:
*******************************************************************
Migration of data for table ZC1CRD_GRM_GRMAP using shadow table
ZC1CRD_GRMAP_SH
*******************************************************************
Declaration of internal tables etc.
DATA: lt_grmres TYPE zc1crd_grm_grmap_t,
lt2_grmres TYPE zc1crd_grm_grmap_t,
lt_messages TYPE salv_wd_t_symsg,
lt_so_tab TYPE REF TO data,
lv_err(1) TYPE c,
ls_msg TYPE symsg.
Declaration of single fields for handling index
DATA: v_current TYPE i.
DATA: v_next TYPE i.
DATA: v_next_date TYPE datum.
DATA: v_next_mapt TYPE zc1_cpmap_type.
DATA: v_next_grmcp TYPE zc1_int_cparty_id.
DATA: v_idx TYPE i.
DATA: v_valid_from TYPE datum.
DATA: v_no_records TYPE i.
Work area declarations
CHT4948
We need 2 workareas in order to compare and check for break of date intervals.
Finally we need a third workarea to write the new data to
DATA: wa_grmres TYPE zc1crd_grm_grmap_s.
DATA: wa2_grmres TYPE zc1crd_grm_grmap_s.
DATA: wa3_grmres TYPE zc1crd_grm_grmap_s.
Shadowtable must be empty
DELETE FROM zc1crd_grmap_sh.
Select data
Inserted Where is for test purpose only
SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_grmres
FROM zc1crd_grm_grmap
WHERE mdm_cparty_grpid GE 'B00000191033'
AND mdm_cparty_grpid LE 'B00000191033'.
WHERE mdm_cparty_grpid GE 'B00000191165'
AND mdm_cparty_grpid LE 'B00000191171'.
Sort by counterparty ID, mapping type, valid from date and GRM CP ID
SORT lt_grmres BY mdm_cparty_grpid cpmap_type valid_from_date grm_int_cpgrp_id.
Get data for workareas
LOOP AT lt_grmres INTO wa_grmres.
v_current = sy-tabix.
v_next = v_current.
We need to be one record ahead in wa2 for comparison
Here for both valid_to_date and mapping type and GRM CP ID
ADD 1 TO v_next.
v_next_date = wa_grmres-valid_to_date + 1.
v_next_mapt = wa_grmres-cpmap_type + 1.
v_next_grmcp = wa_grmres-grm_int_cpgrp_id. "wa_grmres-grm_int_cpgrp_id.
Then read data to the second workarea (wa2) for comparison re. date-break
READ TABLE lt_grmres INTO wa2_grmres INDEX v_next.
v_next_grmcp = wa2_grmres-grm_int_cpgrp_id.
The Valid From Field is set to initial after append of record. Then check field
for IS INITIAL and write the valid from for the first record to v_valid_from
IF v_valid_from IS INITIAL.
MOVE wa_grmres-valid_from_date TO v_valid_from.
ENDIF.
Here we check for any breaks in date intervals, Mapping Types and GRM CP ID
If we have a break, then modify existing appended record with the NEXT record
Clean the char fields for blanks before compare. Just in case.
CONDENSE : wa2_grmres-grm_int_cpgrp_id ,
v_next_grmcp.
IF wa2_grmres-valid_from_date NE v_next_date.
IF wa2_grmres-cpmap_type NE v_next_mapt.
IF wa2_grmres-grm_int_cpgrp_id NE v_next_grmcp.
MOVE wa_grmres-cpmap_type TO wa3_grmres-cpmap_type.
MOVE wa_grmres-valid_to_date TO wa3_grmres-valid_to_date.
MOVE wa_grmres-grm_int_cpgrp_id TO wa3_grmres-grm_int_cpgrp_id.
MOVE wa_grmres-chng_date TO wa3_grmres-chng_date.
MOVE wa_grmres-chng_time TO wa3_grmres-chng_time.
MOVE wa_grmres-chng_user TO wa3_grmres-chng_user.
MODIFY lt2_grmres INDEX v_current FROM wa3_grmres.
MOVE wa_grmres-mdm_cparty_grpid TO wa3_grmres-mdm_cparty_grpid.
MOVE wa_grmres-cpmap_type TO wa3_grmres-cpmap_type.
MOVE v_valid_from TO wa3_grmres-valid_from_date.
APPEND wa3_grmres TO lt2_grmres.
After a new merged record has been inserted, we have to clear the VF-date field (INITIAL)
CLEAR v_valid_from.
We add 1 to the number of records that have been inserted till now
v_no_records = v_no_records + 1.
If we have no breaks in dates then keep overwriting until last record
for the same id
ELSE.
MOVE wa_grmres-valid_to_date TO wa3_grmres-valid_to_date.
MOVE wa_grmres-cpmap_type TO wa3_grmres-cpmap_type.
MOVE wa_grmres-valid_to_date TO wa3_grmres-valid_to_date.
MOVE wa_grmres-grm_int_cpgrp_id TO wa_grmres-grm_int_cpgrp_id.
MOVE wa_grmres-chng_date TO wa3_grmres-chng_date.
MOVE wa_grmres-chng_time TO wa3_grmres-chng_time.
MOVE wa_grmres-chng_user TO wa3_grmres-chng_user.
MODIFY lt2_grmres INDEX v_current FROM wa3_grmres.
ENDIF.
ENDIF.
ENDIF.
2010 Nov 30 12:29 PM
Hi,
What is this structure (zc1crd_grm_grmap_s) having fields.
the field (grm_int_cpgrp_id) in the structre (zc1crd_grm_grmap_s ) have the same data type as of v_next_grmcp .
One more thing you can do is the declaration of v_next_grmcp you can change like this
data :v_next_grmcp like zc1crd_grm_grmap_s-grm_int_cpgrp_id .
Regards,
Nagaraj
2010 Nov 30 12:38 PM
The fields of the structure is matching the db table fields.
The datatype is CHAR12.
I will try the suggested declaration.
Peter
2010 Nov 30 12:23 PM
Hi
Okay. Now, how are these 2 declared?
zc1crd_grm_grmap_t, zc1_int_cparty_id
Regards
Raj
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |