Skip to Content
author's profile photo Former Member
Former Member

Help with the code

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 ?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Nov 25, 2004 at 02:46 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 25, 2004 at 09:33 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.