2016 Aug 17 10:23 PM
Hi Members ,
I have a requirement in which numerous validations have to applied before passing the values to a BAPI . i have to find a way to know checktable assigned to a field dynamically . I will explain it more clearly now .
eg . There is a structure KOMK . It has 363 fields in these fields around 200 have a check table assigned to them .
The requirement is to check the value in the excel sheet provided by user to first validated before passing to BAPI .
eg . if it is sales organisation . field : VKORG . The value provided by user should be in table TVKO which is checktable for this field ( displayed in Inputc help/check tab ) . In this way there are numerous other fields whose checks need to be applied . Plz Refer to screenshot below :
i have the names of fields like VKORG , VTWEG , BRSCH stored in character in a internal table in one single column .
i am looking for a dynamic way to find check table so that i can take care of 200+ fields. Maintaing these in Ztable is not an option for me frz .
Is it stored in some table or Link of tables or View or some Function Module .....
How to fulfill this Requirement ?
Would be grateful to your Replies ....
Kindly comment .
Thanks & Rgds ,
Dave
2016 Aug 18 1:05 AM
2016 Aug 18 2:18 AM
Hi Devendra,
You can make use of table DD03L to get information about the checktable of a particular field of a standard table.
Regards,
Richa
2016 Aug 20 9:44 AM
Hi Richa ,
Thanks for the Reply . Can you plz help me the use of the FM suggested by Raymond / Loyd to achieve the objective . My query i just posted as the latest reply and you can find that in trail in the Post .
Thanks & Rgds ,
Devendra Singh
2016 Aug 18 7:09 AM
I don't understand the requirement to do the checks before calling the BAPI. Doesn't the BAPI check the values too?
Foreign keys are primarily stored in tables DD08L and DD05S (value in field DD03L-CHECKTABLE being redundant with DD08L-CHECKTABLE)
2016 Aug 20 9:48 AM
Hi Sandra / Members ,
Thanks for the Reply . The BAPI i am using doesnot check for various fields so i have to apply this procedure of checking the value before passing BAPI . FM DDUT_INPUT_CHECK solved the issue .
Thanks & Rgds ,
Devendra Singh
2016 Aug 18 7:33 AM
2016 Aug 20 9:37 AM
Hi Raymond ,
Thanks so much Raymond for suggesting the FM . I used it successfully to achieve the objective.
Grt !!
Rgds ,
Devendra Singh
2016 Aug 18 7:51 AM
Devendra,
Can you please let us know what compelled you to take this approach of validating the field names with the respective check table field names ?
K.Kiran.
2016 Aug 18 2:40 PM
Devendra,
You have an ITAB with the fieldnames you want to check, so may I suggest something along these lines:
Add another field to that ITAB with the poistion in the DB table for each field. Then you can "walk" across each data record field by field and see what needs to be checked.
In the below example, I used funciton module DDUT_INPUT_CHECK that Raymond suggested in his earlier comment. The FM has fairly good documentation. Error handling can be done with the FAILURE_TAB or with the MSG procedure (which brings back the error text used in the FK check) or with the simple sy-subrc check I used - whatever fits your needs.
Good luck!
Loyd
DATA: wa_spfli TYPE spfli,
it_spfli TYPE STANDARD TABLE OF spfli.
DATA: repid TYPE sy-repid.
DATA: BEGIN OF wa_fields, "ITAB of fields to be checked
pos TYPE dd03l-position,
fieldname TYPE dfies-lfieldname, "datatype is important to FM
END OF wa_fields,
it_fields LIKE STANDARD TABLE OF wa_fields.
FIELD-SYMBOLS: <fs_comp> TYPE any. "used to walk across the structure
INITIALIZATION. "load the ITAB of fields to be checked
wa_fields-pos = '5'.
wa_fields-fieldname = 'CITYFROM'.
APPEND wa_fields TO it_fields.
wa_fields-pos = '8'.
wa_fields-fieldname = 'CITYTO'.
APPEND wa_fields TO it_fields.
START-OF-SELECTION.
repid = sy-repid.
SELECT * FROM spfli INTO TABLE it_spfli. "get the real data
LOOP AT it_spfli INTO wa_spfli.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_spfli TO <fs_comp>. "walk the struktur
IF sy-subrc <> 0.
EXIT.
ENDIF.
CLEAR wa_fields.
READ TABLE it_fields INTO wa_fields WITH KEY pos = sy-index.
IF sy-subrc = 0. "found a hit on ITAB
CALL FUNCTION 'DDUT_INPUT_CHECK'
EXPORTING
tabname = 'SPFLI'
fieldname = wa_fields-fieldname
calling_program = repid
value = <fs_comp>
EXCEPTIONS
no_ddic_field = 1
illegal_move = 2
OTHERS = 3.
IF sy-subrc <> 0.
WRITE: 'failed check', wa_fields-fieldname, <fs_comp>.
ENDIF.
ENDIF.
ENDDO.
ENDLOOP.
2016 Aug 20 9:33 AM
Hi Loyd / ABAP members ,
Thanks so much Loyd for the Reply . I used your code to achieve the objective . However , I am facing an issue . It gives sy-subrc as zero ( success ) just after function module , even if i pass a value which is not maintained in check table . i mean i changed the value in degubber to a wrong value for CITYFROM which is not maintained in it checktable which is SGEOCITY to check for the error message , however it is always returning sy-subrc as zero . My error record when it is there in internal table it_spfli which i have maintained at runtime in <fs_comp> is not triggering sy-subrc as non-zero value . I have tried all these combination to reperesent tabname / strucname :
CALL FUNCTION 'DDUT_INPUT_CHECK'
EXPORTING
TABNAME = 'SPFLI'
" TABNAME = 'WA_SPFLI' commented
" STRUCNAME = 'WA_SPFLI' commented
" STRUCNAME = 'SPFLI' commented
fieldname = wa_fields-fieldname
calling_program = repid
value = <fs_comp>
EXCEPTIONS
no_ddic_field = 1
illegal_move = 2
OTHERS = 3.
IF sy-subrc <> 0.
WRITE: 'failed check', wa_fields-fieldname, <fs_comp>.
ENDIF.
However , the issue persists . What mistake i am making . I also tried to debug but couldnot figure out . The code i am using which is the same as of Loyd gave & is rewritten below ( also attached with post )
Loyd / other members plz help .
Would be grateful for your Replies .
Thanks & Rgds ,
Devendra Singh
================================================================
REPORT ZTEST_INPUTCHECK.
DATA: wa_spfli TYPE spfli,
it_spfli TYPE STANDARD TABLE OF spfli.
DATA: repid TYPE sy-repid.
DATA: BEGIN OF wa_fields, "ITAB of fields to be checked
pos TYPE dd03l-position,
fieldname TYPE dfies-lfieldname, "datatype is important to FM
END OF wa_fields,
it_fields LIKE STANDARD TABLE OF wa_fields.
FIELD-SYMBOLS: <fs_comp> TYPE any. "used to walk across the structure
INITIALIZATION. "load the ITAB of fields to be checked
wa_fields-pos = '5'.
wa_fields-fieldname = 'CITYFROM'.
APPEND wa_fields TO it_fields.
wa_fields-pos = '8'.
wa_fields-fieldname = 'CITYTO'.
APPEND wa_fields TO it_fields.
START-OF-SELECTION.
repid = sy-repid.
SELECT * FROM spfli INTO TABLE it_spfli. "get the real data
BREAK-POINT .
LOOP AT it_spfli INTO wa_spfli.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_spfli TO <fs_comp>. "walk the struktur
IF sy-subrc <> 0.
EXIT.
ENDIF.
CLEAR wa_fields.
READ TABLE it_fields INTO wa_fields WITH KEY pos = sy-index.
BREAK-POINT .
IF sy-subrc = 0. "found a hit on ITAB
CALL FUNCTION 'DDUT_INPUT_CHECK'
EXPORTING
TABNAME = 'SPFLI'
"TABNAME = 'WA_SPFLI' " commented
"STRUCNAME = 'WA_SPFLI' " commented
"STRUCNAME = 'SPFLI' "commented
fieldname = wa_fields-fieldname
calling_program = repid
value = <fs_comp>
EXCEPTIONS
no_ddic_field = 1
illegal_move = 2
OTHERS = 3.
IF sy-subrc <> 0.
WRITE: 'failed check', wa_fields-fieldname, <fs_comp>.
ENDIF.
ENDIF.
ENDDO.
ENDLOOP.
BREAK-POINT .
**** CALL FUNCTION 'DDUT_INPUT_CHECK'
***** EXPORTING
***** TABNAME =
***** FIELDNAME =
***** CALLING_PROGRAM =
***** STRUCNAME =
***** VALUE =
***** VALUE_IS_EXTERNAL = ' '
***** ACCEPT_ALL_INITIAL = ' '
***** VALUE_LIST =
***** NO_FORKEY_CHECK = ' '
***** IMPORTING
***** MSGID =
***** MSGTY =
***** MSGNO =
***** MSGV1 =
***** MSGV2 =
***** MSGV3 =
***** MSGV4 =
***** VALUE_INTERNAL =
***** TABLES
***** FAILURE_TAB =
***** CHANGING
***** ADDITIONAL_FIELDS =
***** EXCEPTIONS
***** NO_DDIC_FIELD = 1
***** ILLEGAL_MOVE = 2
***** OTHERS = 3
**** .
**** IF SY-SUBRC <> 0.
***** Implement suitable error handling here
**** ENDIF.
****
****
2016 Aug 20 1:29 PM
Thanks Loyd . I got the solution . In your code i have to check MSGTY also .
CALL FUNCTION 'DDUT_INPUT_CHECK'
EXPORTING
" TABNAME = 'SPFLI'
" TABNAME = 'WA_SPFLI'
STRUCNAME = 'WA_SPFLI'
"STRUCNAME = 'SPFLI'
fieldname = wa_fields-fieldname
calling_program = repid
value = <fs_comp>
" value_is_external = 'X'
IMPORTING
MSGID = MSGID
MSGTY = MSGTY
MSGNO = MSGNO
MSGV1 = MSGV1
MSGV2 = MSGV2
MSGV3 = MSGV3
MSGV4 = MSGV4
" VALUE_INTERNAL =
EXCEPTIONS
no_ddic_field = 1
illegal_move = 2
OTHERS = 3.
IF MSGTY EQ 'E'.
WRITE: 'failed check', wa_fields-fieldname, <fs_comp>.
ENDIF.
Grt !!
Rgds ,
Devendra Singh
2016 Aug 22 5:14 PM