Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Help with the code

Former Member
0 Kudos

First check
I want to write a code to check the whether the following fields are present in TKVST table.

If SPRAS(language) has D, then The VERSI(Version) and VTEXT(description) should have the following values


SPRAS VERSI VTEXT

D 000 plan/Ist-version
D 001 Plan version änderung 1
D 002 plan version änderung 2
D 003 plan verison änderung 3


if SPRAS value is E then,The table TKVS must have the following values

SPRAS VERSI VTEXT

E 000 plan/Ist-version
E 001 Plan version revision 1
E 002 plan version revision 2
E 003 plan verison revision 3

Second Check2


VERSI should not have a values from 004-009

third check3

VERSI can have values 100 and Above ?

2 REPLIES 2

Former Member
0 Kudos

Hi Oliver

The code sample here must give you a clue on how to do it. I did not use any performs to compress the code, but herewith it is better understandable:

DATA: itab TYPE tkvst OCCURS 0,

wtab TYPE tkvst.

SELECT *

INTO itab

FROM tkvst

WHERE spras CO 'DE'.

IF sy-subrc EQ 0.

LOOP AT itab INTO wtab

WHERE spras EQ 'D'.

CASE wtab-versi.

WHEN '000'.

IF wtab-vtext NE 'plan/Ist-version'.

WRITE: / 'Error: ', wtab.

ELSE.

  • No error

ENDIF.

WHEN '001'.

IF wtab-vtext NE 'Plan version änderung 1'.

WRITE: / 'Error: ', wtab.

ELSE.

  • No error

ENDIF.

WHEN '002'.

IF wtab-vtext NE 'plan version änderung 2'.

WRITE: / 'Error: ', wtab.

ELSE.

  • No error

ENDIF.

WHEN '003'.

IF wtab-vtext NE 'plan verison änderung 3'.

WRITE: / 'Error: ', wtab.

ELSE.

  • No error

ENDIF.

WHEN '004' OR '005' OR '006' OR '007' OR '008' OR '009'.

WRITE: / 'Error: ', wtab.

WHEN OTHERS.

  • No Error

ENDCASE.

ENDLOOP.

LOOP AT itab INTO wtab

WHERE spras EQ 'D'.

CASE wtab-versi.

WHEN '000'.

IF wtab-vtext NE 'plan/Ist-version'.

WRITE: / 'Error: ', wtab.

ELSE.

  • No error

ENDIF.

WHEN '001'.

IF wtab-vtext NE 'Plan version revision 1'.

WRITE: / 'Error: ', wtab.

ELSE.

  • No error

ENDIF.

WHEN '002'.

IF wtab-vtext NE 'Plan version revision 2'.

WRITE: / 'Error: ', wtab.

ELSE.

  • No error

ENDIF.

WHEN '003'.

IF wtab-vtext NE 'Plan version revision 3'.

WRITE: / 'Error: ', wtab.

ELSE.

  • No error

ENDIF.

WHEN '004' OR '005' OR '006' OR '007' OR '008' OR '009'.

WRITE: / 'Error: ', wtab.

WHEN OTHERS.

  • No Error

ENDCASE.

ENDLOOP.

ENDIF.

Hope this helps you,

Regards,

Rob.

ssimsekler
Active Contributor
0 Kudos

Hi

Just some additions to Rob's code, I have this;


*--I do not know the structure of the table TKVST, if it 
*--contains just these three fields; use
*-- DATA lt_itab LIKE tkvst OCCURS 0 WITH HEADER LINE .
DATA: BEGIN OF lt_itab OCCURS 0 ,
        spras LIKE tkvst-spras  ,
        versi LIKE tkvst-versi  ,
        vtext LIKE tkvst-vtext  ,
      END OF lt_itab            .

SELECT spras versi vtext FROM tkvst
       INTO TABLE lt_itab
       WHERE ( spras = 'D' OR
               spras = 'E' ) AND
             ( versi = '000' OR
               versi = '001' OR
               versi = '002' OR
               versi = '003' ) .
*--1st check
* << --<b>A</b>
READ TABLE lt_itab with key spras = 'D'
                            versi = '000'
                            vtext = 'plan/lst-version' .
IF sy-subrc NE 0 .
*--Here generate error
ENDIF .
* >> --<b>A</b>

*--You can copy and adapt the code part A above to check
*--other conditions for your <i>"first check"</i>. Or
*--the best is; write it as a macro or a subroutine and
*--call respectively.


*--I do not know the data volume for the table TKVST.
*--Depending on an analysis, you can choose to get all 
*--its content into your internal table as Rob did and 
*--then make your checks for <i>"second check"</i> and 
*--<i>"third check"</i>
*--OR
*--Just use 'SELECT SINGLE's to check as I will do here

DATA lv_versi_for_check LIKE tkvst-versi .
*--2nd check
SELECT SINGLE versi FROM tkvst
       INTO lv_versi_for_check
       WHERE versi BETWEEN '004' AND '009' .
IF sy-subrc = 0 .
*--Check fails
ENDIF .

*--2nd check
SELECT SINGLE versi FROM tkvst
       INTO lv_versi_for_check
       WHERE versi GE '100' .
IF sy-subrc = 0 .
*--Check result
ENDIF .

Hope this clarifies some more about your requirement.

*--Serdar