Inverse of count

I have the below data set -
Order_id Item Qty
1 A1 3
2 A2 2
3 A3 3
My desired output (With only one SQL query) is mentioned below-
Order_id Item Qty
1 A1 1
1 A1 1
1 A1 1
2 A2 1
2 A2 1
3 A3 1
3 A3 1
3 A3 1
How do I do this?

Another way would be :
SQL> with sample_data as (
  2   select 1 order_id, 'A1' item, 3 qty from dual union all
  3   select 2, 'A2', 2 from dual union all
  4   select 3, 'A3', 3 from dual
  5  )
  6  select t1.order_id
  7       , t1.item
  8       , t2.column_value as qty
  9  from sample_data t1
10     , table(
11         cast(
12           multiset(
13             select 1 from dual connect by level <= t1.qty
14           ) as sys.odcinumberlist
15         )
16       ) t2
17  ;
  ORDER_ID ITEM        QTY
         1 A1            1
         1 A1            1
         1 A1            1
         2 A2            1
         2 A2            1
         3 A3            1
         3 A3            1
         3 A3            1
8 rows selected
or, using recursive subquery factoring (11.2) :
SQL> with sample_data as (
  2   select 1 order_id, 'A1' item, 3 qty from dual union all
  3   select 2, 'A2', 2 from dual union all
  4   select 3, 'A3', 3 from dual
  5  ),
  6  dataset (order_id, item, qty, sofar) as
  7  (
  8    select order_id
  9         , item
10         , qty
11         , 1
12    from sample_data
13    union all
14    select order_id, item, qty, sofar+1
15    from dataset
16    where sofar < qty
17  )
18  search depth first by order_id set seq
19  select order_id, item, 1 as qty
20  from dataset
21  ;
  ORDER_ID ITEM        QTY
         1 A1            1
         1 A1            1
         1 A1            1
         2 A2            1
         2 A2            1
         3 A3            1
         3 A3            1
         3 A3            1
8 rows selected

Similar Messages

  • How to apply inverse of head/tail

    It seems as if I find myself wanting to extract the inverted selection of head or tail almost as often as I do the normal selection. Ie, I want to filter *out* the first or last n lines of some standard input. Is there a simple way to do this, aside from writing a short script to get the line count, then head/tailing off the complement of what I want? I wish head and tail had the grep equivalent of -v.

    From what I understand, the inverse of
    head -n 25 file
    would be
    tail -n +25 file
    and the inverse of
    tail -n 25 file
    would be
    head -n -25 file
    Is this what you want?

  • Can a counter source be inverted on the 6229

    Can counter a source, for example "Dev1/Ctr0InternalOutput", be inverted on the 6229.  Currently, when I used the following line,
    DAQmxConnectTerms ("/Dev1/Ctr0InternalOutput", "/Dev1/PFI4", DAQmx_Val_InvertPolarity);
    I received an error stating that the hardware thus support inversion.  Thus the problem lies in the source or the destintation terminal?

    Hi cscp,
    The 6229 does not have general purpose inverters available for such
    signal paths, and therefore is not capable of signal inversion as part
    of the DAQmxConnectTerms function call.
    As part of the functionality of the on-board counters, however, the 6229 DOES have the ability to set the polarity of the counter output event.  Use the following function call:
    DAQmxSetExportedCtrOutEventPulsePolarity(TaskHandle taskHandle, int32 data);
    setting the data parameter to DAQmx_Val_ActiveLow (10096).
    Hopefully this helps out.  If not, let me know, and we can keep
    working to get this issue fixed.  Best of luck on the application.
    Have a great day!
    Travis W

  • Use counter to control digital IO?

    I'm new to Labview and using a PCI 6010.  I'd like to generate two finite digital pulse trains such that one is in the 'on' position while the other is in the 'off position' and vice versa.  The pulse trains will have the same frequency and opposite duty cycles (ie if duty cycle is 0.2 the other is 0.8).
    I've gotten a single pulse train using a counter output and the example Dig Pulse Train-Finite vi, but am having trouble getting the second pulse train.
    Things I've tried unsuccessfully:
    1. Use DAQ Assistant to generate two pulse trains using two counter outputs, while delaying one train so that they're inverted.
    2. Use two counter outputs where one displays the inverse of the other
    3. Use one counter to generate pulse, invert pulse, and use a digital output to send inverted pulse
    4. Simulate square wave, send to one digital output, while sending the inverse square wave to another digital output.
    I would assume that some of these methods are simply not possible, but I'm not sure which to pursue further.  I would appreciate any advice on the simplest strategy to achieve my desired output.  Thanks.

    Hello jman1,
    Since this was a duplicate post, please refer to the original issue/post included below. For the purposes of making the forums/solutions searchable for the community, please reserve creating new form posts for new issues. Thank you
    1. Synchronized finite digital pulse trains: http://forums.ni.com/ni/board/message?board.id=170&message.id=480738#M480738
    Regards,
    Ali M
    Applications Engineer
    National Instruments 
    Message Edited by Ali M on 03-09-2010 07:43 PM
    Message Edited by Ali M on 03-09-2010 07:44 PM

  • Counter / timer PXI6602

    Support:
    NI PXI 1002 AC, Labview 5.1, NI DAQ 681,
    Devices: PXI 6602, 6025 E, 6508
    My question is to synchronise 4 counters in mode "count events" during 100ms, on PXI 6602 with counter 1 in mode "pulse train generation" 50 Hz on PXI 6025 E.
    How can J find the level HIGH / LOW of OUT pin counter 1 PXI 6025 E to control the GATE pin of the 4 counters in mode "count events" on PXI 6602, without hard connecting.
    Evently, it could be a another solution with inverse control like the control of 6025 E by 6602.
    thanks for your answers
    Applications Sample: http://digital.ni.com/worldwide/france.nsf/5c487167f30a8c86862564ce00661be4/2ca4e93dc3d774e58025694900523020?OpenDocument

    You can use Route Signal.vi in LabVIEW (or the NI-DAQ function Select_Signal) to route the OUT of the 6025E counter 1 to a RTSI pin. Then you can call the function using the 6602's device number and select the source of the counters' GATE to be RTSI 0.
    In LabVIEW you can use the Set Attribute function to select the gate source. Or you can call the NI-DAQ function GPCTR_Change_Parameter.
    Here is also a link that describes how RTSI is implemented for PXI DAQ Devices:
    http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/ef034aada86d9b9a862565b6002e5ca9?OpenDocument

  • Inverse relationships silently failing with dual queries

    Now this is a really weird one. (2.2.3, 1.3.1_03, w2k)
    I have some test code to do simple queries
    public Project findProjectByName(String name) {
    return (Project) findByName(Project.class, name);
    public User findUserByName(String name) {
    return (User) findByName(User.class, name);
    private Object findByName(Class clazz, String name) {
    Extent extent = pm.getExtent(clazz, true);
    Query query = pm.newQuery(clazz, extent, "this.name == name");
    query.declareParameters("String name");
    Collection results = (Collection) query.execute(name);
    if (results.size() != 1) {
    throw new IllegalStateException("wrong result count " +
    results.size() + " of " + clazz.getName() + ": " +
    name);
    Object result = results.iterator().next();
    query.closeAll();
    return result;
    and some relationships defined
    which has relationships defined as
    <class name="Permission"/>
    <class name="Project" requires-extent="true">
    <field name="permissions">
    <collection element-type="Permission"/>
    <extension vendor-name="kodo" key="inverse"
    value="project"/>
    </field>
    </class>
    <class name="User" requires-extent="true">
    <field name="permissions">
    <collection element-type="Permission"/>
    <extension vendor-name="kodo" key="inverse" value="user"/>
    </field>
    </class>
    and some code which uses it.
    Project itpap = findProjectByName("itpap");
    User geoff = findUserByName("geoff");
    System.out.println("itpap: permissions" + itpap.getPermissions());
    System.out.println("geoff: permissions" + geoff.getPermissions());
    Problem is, it prints out:
    itpap: permissions[com.cisco.apit.itpap.model.Permission@6c6696,
    com.cisco.apit.itpap.model.Permission@431340]
    geoff: permissions[]
    That is, the inverse relationship for the User object seems to be silently
    failing.
    So I tried reversing the order of the find methods, like so:
    User geoff = mm.findUserByName("geoff");
    Project itpap = mm.findProjectByName("itpap");
    System.out.println("itpap: permissions" + itpap.getPermissions());
    System.out.println("geoff: permissions" + geoff.getPermissions());
    Same problem.
    Then, I tried modifying it to:
    Project itpap = findProjectByName("itpap");
    System.out.println("itpap: permissions" + itpap.getPermissions());
    User geoff = findUserByName("geoff");
    System.out.println("geoff: permissions" + geoff.getPermissions());
    And now it works fine, I get
    itpap: permissions[com.cisco.apit.itpap.model.Permission@4247a0,
    com.cisco.apit.itpap.model.Permission@6c6696]
    geoff: permissions[com.cisco.apit.itpap.model.Permission@2bb7e0,
    com.cisco.apit.itpap.model.Permission@6c6696]
    How weird is that? It seems like the syptoms would be best descibed by "if
    you query for two objects separately, then navigating to a related object
    from one of the queried objects breaks any subsequent attempted navigation
    to a related objects for the other".
    Cheers
    Geoff

    Hi Geoff,
    Check out my posts on "2.2.3GA Transparent Navigation of two-way one-to-one relationship failing"
    (March 9th and following.) Sounds like we may be looking at the same bug. I don't know if this has
    been fixed in 2.2.4.
    David
    Geoff Soutter wrote:
    >
    Now this is a really weird one. (2.2.3, 1.3.1_03, w2k)
    I have some test code to do simple queries
    public Project findProjectByName(String name) {
    return (Project) findByName(Project.class, name);
    public User findUserByName(String name) {
    return (User) findByName(User.class, name);
    private Object findByName(Class clazz, String name) {
    Extent extent = pm.getExtent(clazz, true);
    Query query = pm.newQuery(clazz, extent, "this.name == name");
    query.declareParameters("String name");
    Collection results = (Collection) query.execute(name);
    if (results.size() != 1) {
    throw new IllegalStateException("wrong result count " +
    results.size() + " of " + clazz.getName() + ": " +
    name);
    Object result = results.iterator().next();
    query.closeAll();
    return result;
    and some relationships defined
    which has relationships defined as
    <class name="Permission"/>
    <class name="Project" requires-extent="true">
    <field name="permissions">
    <collection element-type="Permission"/>
    <extension vendor-name="kodo" key="inverse"
    value="project"/>
    </field>
    </class>
    <class name="User" requires-extent="true">
    <field name="permissions">
    <collection element-type="Permission"/>
    <extension vendor-name="kodo" key="inverse" value="user"/>
    </field>
    </class>
    and some code which uses it.
    Project itpap = findProjectByName("itpap");
    User geoff = findUserByName("geoff");
    System.out.println("itpap: permissions" + itpap.getPermissions());
    System.out.println("geoff: permissions" + geoff.getPermissions());
    Problem is, it prints out:
    itpap: permissions[com.cisco.apit.itpap.model.Permission@6c6696,
    com.cisco.apit.itpap.model.Permission@431340]
    geoff: permissions[]
    That is, the inverse relationship for the User object seems to be silently
    failing.
    So I tried reversing the order of the find methods, like so:
    User geoff = mm.findUserByName("geoff");
    Project itpap = mm.findProjectByName("itpap");
    System.out.println("itpap: permissions" + itpap.getPermissions());
    System.out.println("geoff: permissions" + geoff.getPermissions());
    Same problem.
    Then, I tried modifying it to:
    Project itpap = findProjectByName("itpap");
    System.out.println("itpap: permissions" + itpap.getPermissions());
    User geoff = findUserByName("geoff");
    System.out.println("geoff: permissions" + geoff.getPermissions());
    And now it works fine, I get
    itpap: permissions[com.cisco.apit.itpap.model.Permission@4247a0,
    com.cisco.apit.itpap.model.Permission@6c6696]
    geoff: permissions[com.cisco.apit.itpap.model.Permission@2bb7e0,
    com.cisco.apit.itpap.model.Permission@6c6696]
    How weird is that? It seems like the syptoms would be best descibed by "if
    you query for two objects separately, then navigating to a related object
    from one of the queried objects breaks any subsequent attempted navigation
    to a related objects for the other".
    Cheers
    Geoff

  • Routine to count unique values

    Hi Gurus,
    I am BI user,  I am trying to write a routine to populate count if employee and month from source fields is unique.
    For example:
    Employee   calmonth       count
    10000          01.2008         1
    10000          02.2008         1
    10001          01.2008         1
    10000          01.2008         0
    Please can you help me with the code and any suggestions to write the code.
    Regards,
    Reddy.

    Hi Eric,
    Below is my code, count is always showing "0".
          CLASS routine IMPLEMENTATION
    CLASS lcl_transform IMPLEMENTATION.
      METHOD compute_0HDCNT_LAST.
      IMPORTING
        request     type rsrequest
        datapackid  type rsdatapid
        SOURCE_FIELDS-PERSONAL_NO TYPE N LENGTH 000008
        SOURCE_FIELDS-ZZMONTH TYPE C LENGTH 000007
       EXPORTING
         RESULT type tys_TG_1-HDCNT_LAST
        DATA:
          MONITOR_REC    TYPE rsmonitor.
    $$ begin of routine - insert your code only below this line        -
    TYPES:
    BEGIN of ty_itab,
    PERSONAL_NO(8) type n,
    ZZMONTH(7) type c,
    count(1) type c,
    end of ty_itab.
    data: itab type table of ty_itab.
    field-symbols : <line> type ty_itab.
    append SOURCE_FIELDS-PERSONAL_NO to itab.
    append SOURCE_FIELDS-ZZMONTH  to itab.
    sort itab by PERSONAL_NO ZZMONTH.
    loop at itab assigning <line>.
    <line>-count = '0'.
    AT NEW ZZMONTH.
    <line>-count = '1'.
    ENDAT.
    endloop.
    $$ end of routine - insert your code only before this line         -
      ENDMETHOD.                    "compute_0HDCNT_LAST
          Method invert_0HDCNT_LAST
          This subroutine needs to be implemented only for direct access
          (for better performance) and for the Report/Report Interface
          (drill through).
          The inverse routine should transform a projection and
          a selection for the target to a projection and a selection
          for the source, respectively.
          If the implementation remains empty all fields are filled and
          all values are selected.
      METHOD invert_0HDCNT_LAST.
    $$ begin of inverse routine - insert your code only below this line-
    ... "insert your code here
    $$ end of inverse routine - insert your code only before this line -
      ENDMETHOD.                    "invert_0HDCNT_LAST
    ENDCLASS.                    "routine IMPLEMENTATION

  • Counter stops sampling during several-minute acquisitions

    Hello All,
        I am working on rewriting a data-acquisition program for DAQmx.  The code was originally written for traditional DAQ, but ceased working when we upgraded to LabView 8.5 and the corresponding version of DAQmx.  The program is designed to sample  many accelerometers using one AI Voltage task, and also sample a motor tach sensor and record all this data.  The program works fine right now except sometimes after 2 or 3 minutes of recording, the counter suddenly stops gathering data for no apparent reason.  It's not a timebase overflow error, because I've already dealt with that problem seperately.  I'm hoping someone has encountered similar behavior before and can help me out, because i'm not sure how to proceed with troubleshooting.
        The counter task is a period measurement which runs continuously and takes all the samples from the buffer each time.  This number varies with motor speed (more samples are taken per loop) and also seems to vary 10 or 20% independent of motor speed (luckily this doesnt affect or post processing programs).  Interestingly, i recorded the number of samples taken at one of these "counter stopping events" and found the last few sample numbers were:  947, 981, 964, 2(?!), 0, 0, 0...   I'm hoping the presence of that bizzare 2 helps someone out.
    Here is a picture of the relevant section of this code:
    The sub-vi "Idler MX Config" contains the configuration for the voltage task, and the sub-vi "Idler MX Read" contains the voltage read block, these work fine having been tested over many programs.  It's a work in progress so I apologise for the mess.
    Any advice is greatly appreciated.  The program does work, but this intermittant problem is hampering its usefulness at the moment.
    Tristan Ericson
    Ohio State University Mechanical Engineering
    Dynamics and Vibrations
    201 West 19th Ave Suite N350
    Columbus, OH 43210-1142
    Office: 614-292-9029
    Lab: 614-247-8077
    Fax: 614-292-3163
    "No one is useless in this world who lightens the burden of another." - Charles Dickens

    Thanks for the reply Kevin, you've given me several new things to think about.
    I've done a lot of counter apps and I don't believe you've stumbled on a known issue with the board or driver. 
    - Perhaps you have a noisy tach signal causing an
    error in your counter task?  This could explain *part* of your
    observations.  The other part, well, I would start by suspecting your
    app code.
    > I've checked the tach signal with an oscilloscope, and found it to perform well, additionally the old version of the code never had any problems with it
    - The 10-20% timing variability didn't immediately
    raise any alarms, but the fact that it's independent of motor speed
    *does* trigger some suspicions.  It suggests that spinning your motor
    at different speeds causes your software timing variability to change
    inversely.  Double the speed and a 10% variation in # of period samples
    represents only *half* as much time as the 10% variation meant at the
    original speed.  Something about that relationship doesn't sit right
    with me.  Dunno what exactly to point to, but it's, well, weird.
    > Our motor has a little bit of speed variation (I think <1%) which explans some of it.  I don't believe the software timing is changing much (is there a way to measure this?).  The variability in number of samples with respect to motor speed makes sense to me given the number of pulses passing duing a sampling interval.  at 50 RPM it's 16 or 17 at 3000 RPM it's around 1000. 
    - My guess for why you get an instance of 2 samples
    before getting stuck at 0 is that for some reason, the *prior*
    iteration finished much faster than normal.  Perhaps this is because an
    error was asserted causing a block of time-consuming code to be
    skipped?  Whatever the cause, it's telling you that you looped back
    around so fast that the task didn't have time to buffer the normal ~900
    samples, but only had time for 2.  So I agree, the "2" should be a
    bigger clue than the sequence of 0's.
    >  This is interesting too, is there an easy way to measure the time each loop iteration takes and store it in an array?
    - comment: is that a 10000 second timeout to your counter task?  Is that on purpose?  Really?
    >  Originally I thought the timeout might be to blame for the counter stopping after awhile, so I put some arbitrarily huge number in there to rule it out.  Can this have downsides?
    - just curious -- I notice you don't specify a buffer
    size for the counter task.  Try explicitly setting that to a fairly
    large size (or at least query the size with a property node).  I don't
    know how well DAQmx guesses at a default buffer size for an "Implicit
    Timing" period measurement task.  (It generally does well for
    explicitly timed tasks.)>  This is a good suggestion, I'll try some things along this avenue and get back to you.
    - what does the rest of the loop code do?
    > To the right hand side of what I posted, there's only some file writing code and the end of the loop.  I neglected to mention it, and probably should have, but there's a second while loop in this program running concurrently.  It sends an analog out voltage via out 6704 card every 50ms to control motor speed.  It's completely independent of the rest of the code but might be interfering?
    -Kevin P.
    Tristan Ericson
    Ohio State University Mechanical Engineering
    Dynamics and Vibrations
    201 West 19th Ave Suite N350
    Columbus, OH 43210-1142
    Office: 614-292-9029
    Lab: 614-247-8077
    Fax: 614-292-3163
    "No one is useless in this world who lightens the burden of another." - Charles Dickens

  • Can source and gate used to measure 2 signals using one counter?

    I have one PCI 6602 card to measure measure the frequency. PCI 6602 has 10 channels, in which channel 5 and 10 doesn't have 'source' terminal.
    We have to measure frequency from 16 signals using one PCI 6602.
    From channel 1 to 4 and 6 to 9, we have 8 'Gate' and 8 'Source' terminals.
    We have connected 16 signals to these 16 terminals.
    At any given point of the time we want to measure either 'Gate' signals(8) or  'Source' signals(8).
    Can any provide any guidance to make a program in labview to measure frequency (period) as per above given points?
    Regards
    Vijay

    Hello Vijay,
    It takes one counter for each digital frequency you want to measure and the PCI-6602 has 8 counters total.  This means that the maximum number of digital frequencies you can measure is 8.  If you want to measure 16 frequencies you'll need 16 counters.
    Single counter frequency measurements are made by comparing the board's time base (80 MHz) to an external frequency.  The board counts the number of time base periods that occur during one period of your incoming frequency.  When you configure the board to take a single counter frequency measurement the card routes the time base to the source of the counter and then you connect the frequency you want to measure to the gate of the counter.
    Here are a couple of articles that explain how these measurements are taken and calculated.  (The second article is on period measurements so for frequency measurements you measure period and take the inverse):
    Making Accurate Frequency Measurements
    Period Measurements with a Counter
    There are example programs available in the LabVIEW example finder.  You can locate these by going to Help>> Find Examples... The examples you want is:  Hardware Input and Output>> DAQmx>> Counter Measurements>> Digital Frequency>> Measure Digital Frequency- Low Freq 1 Ctr.vi.
    I hope this explains how counters work and why you need one counter per measurement.
    Cheers,
    Brooks

  • Timed counter in a while loop without overlapping a second while loop

    Hello,
    Like you can see in attached file (waveform_counter.vi), I have a main while loop which makes a waveform graph and I would like to integer an inversed counter (from x seconds to 0) in some cases. I tried with a overlapped while loop, but obviously, when the counter works, the main loop breaks...
    How can I make a sort of time counter without a loop ? I tried with the while loop iteration, every 100 iterations the counter decreases but I don't success.
    Thanks for help.
    Nathalie.
    Attachments:
    waveform_counter.zip ‏55 KB

    Hello Nathalie:
    Please see what I did in the expiration case.
    Please advice if this is a possible solution.
    Attachments:
    waveform_graph 2.zip ‏41 KB

  • Counting only once when a case structure is true in a while loop

    Hi. First time posting here so do pardon me. I have tried searching for answers in the forums along with attempting the solution myself but to no avail.
    Here is the problem. I am trying to collect voltage signals via the DAQ assistant. When a certain threshold voltage is reached, the "true" case would run. I am currently using the shift register along with the while loop hence the output number "numerical 2" would increase as the while loop runs. However, I only want to register a single case as long the voltage is above is above the threshold.
    Eg. When the voltage is above 3V for some time, it registers only a 1. Then the voltage might dip below 3V. The next time the voltage is above 3V again it would register a 2. So on and so forth. I have attached an image of my block diagram below. Thanks for the help!
    Solved!
    Go to Solution.

    Keep the status of the threshold reached in a shift register.  Perform an AND with the inverse of the value in the shift register and your new threshold detection.  The result of the AND goes into your case structure.
    EDIT:  I just threw together this example.  I used a Feedback Node since it would be cleaner.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Threshold Count.png ‏12 KB

  • Minimum Frequency for counter Pulse Frequency Generation

    Hello,
    What is the Minimum Frequency that the Counter Output Pulse Frequency VI can generate?
    If I need to generate a REALLY low frequency pulse train can I do that?
    Thanks
    Dan

    Hi Dan,
    If you don't explicitly specify a timebase, DAQmx will choose a default depending on the initial parameters you set up for CO Pulse Frequency.  For example, the following code should work on any DAQ device with a 32-bit counter and a 100 kHz timebase available (from my first post, 11.64 uHz is the minimum frequency in this scenario).
    So... your 10-100 second periods should be more than achievable.  The inverse of 12uHz is about 23.15 hours.
    If you're on a 24-bit counter the maximum pulse width would only be ~167.77 seconds (2^24/100000), giving a frequency of about 2.98 mHz assuming 50% duty cycle.
    The only way you should be getting an error at the 10-100 second durations that you are describing is if you start the task off at a faster rate (so DAQmx will pick a faster timebase by default) then modify it to output a lower frequency.  Rollover times for the maximum default timebases are as follows:
        E Series:   ~0.839 seconds (24-bit counter, 20 MHz timebase)
        M Series:   ~53.69 seconds (32-bit counter, 80 MHz timebase)
        X Series:    ~42.95 seconds (32-bit counter, 100 MHz timebase)
    If you want to set a different signal source as a timebase, you can do it with a DAQmx Channel Property Node:
    I'm afraid I don't really understand what you are trying to do specifically.  How does this "infinite" pulse length fit within the context of your application?  Why not simply write the line high in software?  What hardware are you using?
    Best Regards,
    John Passiak

  • Inverse BOM !!!

    Do any body have a code for inverse BOM..
    Exporing a child to different parents ( summarized )

    Hai.
    check the links.
    http://www.sap-basis-abap.com/abap009.htm
    http://www.ct-software.com/abap-pool/yprod001.htm
    Logic for Inverse BOM
    http://sap.ittoolbox.com/groups/technical-functional/sap-abap/bom-explosion-for-a-component-1944897
    check  the example code.
    REPORT ZMULTIBOM NO STANDARD PAGE HEADING LINE-SIZE 195
                    LINE-COUNT 60(2) MESSAGE-ID Z1.
    TABLES: MBEW,           "Material Valuation
            MSLB,           "Special stocks with vendor
            MARA,           "Material Master
            MAKT,           "Material Descriptions
            MARD,           "Material Master: Storage Location/Batch Segment
            MAST,           "BOM Header
            STKO,           "BOM Detail
            STPO,           "Bom Components
            STAS.           "BOM Alternative
    Text Elements
    Plant
    SELECT-OPTIONS: S_WERKS FOR MAST-WERKS DEFAULT 'CA',
    Material
                    S_MATNR FOR MAST-MATNR,
    Material Type
                    S_MTART FOR MARA-MTART.
    Base Quantity
    PARAMETERS: S_BASE TYPE I DEFAULT '1'.
    Display up to Level
    PARAMETERS: S_LVL  TYPE I DEFAULT '99'.
    SELECTION-SCREEN SKIP.
    Include Vendor Stock
    PARAMETERS: X_MSLB  AS CHECKBOX.
    DATA: W_MATNR LIKE MAPL-MATNR.
    DATA: PARENT-MATNR LIKE MAST-MATNR,
          CHILD-MATNR LIKE STPO-IDNRK,
          CHILD-WERKS LIKE MAST-WERKS,
          CHILD-STLAL LIKE MAST-STLAL,
          W_MAKTX LIKE MAKT-MAKTX,
          W_STD TYPE P DECIMALS 5,
          W_MAV TYPE P DECIMALS 5,
          W_MENGE TYPE P DECIMALS 3,
          W_LEVEL TYPE I,
          W_DOT(1),
          W_LVL(12),
          W_LVL1(12),
          W_LVL2(2),
          W_COL TYPE I,
          W_LFLAG,
          W_TTL LIKE MARD-LABST.
    DATA: BEGIN OF INT1 OCCURS 50,
            LGORT(6),
            LABST LIKE MARD-LABST,
          END OF INT1.
    IF S_BASE EQ 0.
      S_BASE = 1.
    ENDIF.
    append multi level routing
    SELECT * FROM MAST WHERE WERKS IN S_WERKS AND
         MATNR IN S_MATNR.
      SELECT SINGLE * FROM MARA WHERE MATNR = MAST-MATNR AND
           MTART IN S_MTART.
      IF SY-SUBRC NE 0.
        CONTINUE.
      ENDIF.
      IF MARA-LVORM <> 'X'.
        PARENT-MATNR = MAST-MATNR.
        CHILD-MATNR  = MAST-MATNR.
        CHILD-WERKS  = MAST-WERKS.
        CHILD-STLAL  = MAST-STLAL.
        SELECT SINGLE * FROM MAKT WHERE MATNR = MAST-MATNR AND
             SPRAS = 'E'.
        W_MAKTX = MAKT-MAKTX.
        REFRESH INT1.
        SELECT * FROM MARD WHERE MATNR = MAST-MATNR AND
             WERKS = MAST-WERKS AND
             LABST NE 0.
          MOVE MARD-LGORT TO INT1-LGORT.
          MOVE MARD-LABST TO INT1-LABST.
          APPEND INT1.
        ENDSELECT.
        IF X_MSLB EQ 'X'.
          SELECT * FROM MSLB WHERE MATNR EQ MAST-MATNR AND
               WERKS EQ MAST-WERKS AND
               LBLAB NE 0.
            MOVE MSLB-LIFNR TO INT1-LGORT.
            MOVE MSLB-LBLAB TO INT1-LABST.
            APPEND INT1.
          ENDSELECT.
        ENDIF.
        W_LEVEL = 1.
        NEW-PAGE.
        PERFORM GETCHILD.
      ENDIF.
    ENDSELECT.
    get child parts
    FORM GETCHILD.
      SELECT * FROM STPO WHERE STLNR = MAST-STLNR
            ORDER BY POSNR.
        SELECT SINGLE * FROM STKO WHERE STLNR = STPO-STLNR
              AND STLAL = MAST-STLAL.
        SELECT SINGLE * FROM STAS WHERE STLNR = STPO-STLNR AND
              STLKN = STPO-STLKN AND
              STLAL = MAST-STLAL.
        IF SY-SUBRC EQ 0.
          CLEAR: W_DOT, W_LVL, W_LVL1.
          PERFORM WRT_DTL.
          CHILD-MATNR = STPO-IDNRK.
          W_LEVEL = W_LEVEL + 1.
          IF W_LEVEL <= S_LVL.
            PERFORM SUBCHILD.
          ENDIF.
          W_LEVEL = W_LEVEL - 1.
        ENDIF.
      ENDSELECT.
    ENDFORM.
    get grand children parts
    FORM SUBCHILD.
      SELECT SINGLE * FROM MAST WHERE MATNR = CHILD-MATNR
         AND WERKS = CHILD-WERKS.
      IF SY-SUBRC NE 0.
        EXIT.
      ENDIF.
      SELECT * FROM STPO WHERE STLNR = MAST-STLNR
            ORDER BY POSNR.
        SELECT SINGLE * FROM STKO WHERE STLNR = STPO-STLNR AND
          STLAL = MAST-STLAL.
        SELECT SINGLE * FROM STAS WHERE STLNR = STPO-STLNR AND
            STLKN = STPO-STLKN AND
            STLAL = STKO-STLAL.
          IF SY-SUBRC EQ 0.
            W_DOT = '.'.
            PERFORM WRT_DTL.
            CHILD-MATNR = STPO-IDNRK.
            W_LEVEL = W_LEVEL + 1.
            IF W_LEVEL <= S_LVL.
              PERFORM SUBCHILD.
            ENDIF.
            W_LEVEL = W_LEVEL - 1.
            SHIFT W_LVL.
          ENDIF.
        ENDSELECT.
    ENDFORM.
    TOP-OF-PAGE.
    WRITE:/ SY-DATUM,SY-UZEIT,
           85 'ABC PTE LTD',
          182 'Page', SY-PAGNO.
    WRITE: / SY-REPID,
             75 'BOM STRUCTURE  (WITH LOCATION BALANCES)',
             182 SY-UNAME.
    SKIP.
    CLEAR W_LFLAG.
    WRITE:/ 'Material No.:', PARENT-MATNR,
            60 'Plant    :', MAST-WERKS.
    W_COL = 90.
    CLEAR W_TTL.
    LOOP AT INT1.
      IF W_COL > 195.
        IF W_LFLAG IS INITIAL.
          WRITE:/ 'Description :', W_MAKTX,
               60 'Base Qty :', S_BASE LEFT-JUSTIFIED.
          W_LFLAG = 'X'.
          W_COL = 90.
        ELSE.
          W_COL = 90.
          SKIP.
        ENDIF.
      ENDIF.
      WRITE AT W_COL 'Loc :'.
      W_COL = W_COL + 6.
      WRITE AT W_COL INT1-LGORT.
      W_COL = W_COL + 7.
      WRITE AT W_COL(12) INT1-LABST LEFT-JUSTIFIED.
      W_COL = W_COL + 16.
      W_TTL = W_TTL + INT1-LABST.
    ENDLOOP.
    IF W_LFLAG IS INITIAL.
      WRITE:/ 'Description :', W_MAKTX,
           60 'Base Qty :', S_BASE LEFT-JUSTIFIED,
           90 'Total :', W_TTL LEFT-JUSTIFIED.
    ELSE.
      WRITE AT W_COL 'Total :'.
      W_COL = W_COL + 8.
      WRITE AT W_COL W_TTL LEFT-JUSTIFIED.
    ENDIF.
    SKIP.
    ULINE.
    WRITE: /001 'Level',
            011 'Item',
            017 'Component',
            037 'Description',
            079 '    Per',
            089 'UOM',
            094 ' Std Price',
            106 'Moving Avg',
            119 'Location',
            128 ' Balance',
            139 'Location',
            148 ' Balance',
            159 'Location',
            168 ' Balance',
            179 'Total Quantity'.
    ULINE.
    FORM WRT_DTL.
      CLEAR: MAKT-MAKTX, W_MAV, W_STD.
      SELECT SINGLE * FROM MAKT WHERE MATNR = STPO-IDNRK AND
           SPRAS = 'E'.
      SELECT SINGLE * FROM MBEW WHERE MATNR = STPO-IDNRK AND
           BWKEY = MAST-WERKS.
      IF SY-SUBRC = 0.
        W_MAV = MBEW-VERPR / MBEW-PEINH.
        W_STD = MBEW-STPRS / MBEW-PEINH.
      ENDIF.
      W_MENGE = ( STPO-MENGE / STKO-BMENG ) * S_BASE.
      W_LVL2 = W_LEVEL.
      CONCATENATE W_DOT W_LVL INTO W_LVL.
      CONCATENATE W_LVL W_LVL2 INTO W_LVL1.
      WRITE: /001 W_LVL1,
              011 STPO-POSNR,
              017 STPO-IDNRK,
              037 MAKT-MAKTX,
              079(8) W_MENGE,
              089 STPO-MEINS,
              094(10) W_STD,
              106(10) W_MAV.
      W_COL = 119.
      CLEAR W_TTL.
      SELECT * FROM MARD WHERE MATNR = STPO-IDNRK AND
           WERKS = MAST-WERKS AND
           LABST NE 0.
        IF W_COL > 166.
          W_COL = 119.
          WRITE AT /W_COL ' '.
        ENDIF.
        WRITE AT W_COL MARD-LGORT.
        W_COL = W_COL + 5.
        WRITE AT W_COL(13) MARD-LABST.
        W_COL = W_COL + 15.
        W_TTL = W_TTL + MARD-LABST.
      ENDSELECT.
      IF X_MSLB EQ 'X'.
        SELECT * FROM MSLB WHERE MATNR = STPO-IDNRK AND
             WERKS = MAST-WERKS AND
             LBLAB NE 0.
          IF W_COL > 166.
            W_COL = 119.
            WRITE AT /W_COL ' '.
          ENDIF.
          WRITE AT W_COL(6) MSLB-LIFNR.
          W_COL = W_COL + 6.
          WRITE AT W_COL(12) MSLB-LBLAB.
          W_COL = W_COL + 14.
          W_TTL = W_TTL + MSLB-LBLAB.
        ENDSELECT.
      ENDIF.
      WRITE AT 179(15) W_TTL.
    ENDFORM.
    Regards.
    sowjanya.b

  • Java and Inverse

    Hi,
    Im doing a bit of work on BigIntegers in Java and I am trying to calculate:
    k (inverse) mod p
    I have tried:
    BigInteger e = k.modInverse(p);But this does not work, any idea's how I would do this or am I even asking the right question??
    Thanks

    I think we're talking about different kinds of inversion here. Modular versus Multiplicative.
    public class Test
         public static void main(String[] args)
              int test = 11; //k
              int test2 = 13; //p
              System.out.println("K to the negative 1: " +testOne(test));
              System.out.println("1 divided by k: " +testTwo(test)); //mult
              System.out.println("Inverse of k: " +testThree(test, test2)); //mod
         static double testOne(int k)
              return Math.pow(k, -1);
         static double testTwo(int k)
              return 1/k;
         //W*invW % n = 1
         public static double testThree(int w, int n)
              int count = 2;
              while(!(((w*count)%n) == 1))
                   count ++;
              return count;
    }I guess it all depends on what the OP was trying to do. I'm beginning to think I misunderstood the question he was asking so I'll let it go. =)

  • Fast Inverse Square Root

    I expect no replies to this thread - because there are no
    answers, but I want to raise awareness of a faculty of other
    languages that is missing in Flash that would really help 3D and
    games to be built in Flash.
    Below is an optimisation of the Quake 3 inverse square root
    hack. What does it do? Well in games and 3D we use a lot of vector
    math and that involves calculating normals. To calculate a normal
    you divide a vector's parameters by it's length, the length you
    obtain by pythagoras theorem. But of course division is slow - if
    only there was a way we could get 1.0/Math.sqrt so we could just
    multiply the vector and speed it up.
    Which is what the code below does in Java / Processing. It
    runs at the same speed as Math.sqrt, but for not having to divide,
    that's still a massive speed increase.
    But we can't do this in Flash because there isn't a way to
    convert a Number/float into its integer-bits representation. Please
    could everyone whinge at Adobe about this and give us access to a
    very powerful tool. Even the guys working on Papervision are having
    trouble with this issue.

    that's just an implementation of newton's method for finding
    the zeros of a differentiable function. for a given x whose inverse
    sq rt you want to find, the function is:
    f(y) = 1/(y*y) - x;
    1. you can find the positive zero of f using newton's method.
    2. you only need to consider values of x between 1 and 10
    because you can rewrite x = 10^^E * m, where 1<=m<10.
    3. the inverseRt(x) = 10^^(-E/2) * inverseRt(m)
    4. you don't have to divide E by 2. you can use bitwise shift
    to the right by 1.
    5. you don't have to multiply 10^^(-E/2) by inverseRt(m): you
    can use a decimal shift of inverseRt(m);
    6. your left to find the positive zero of f(y) = 1/(y*y) - m,
    1<=m<10.
    and at this point i realized what, i believe, is a much
    faster way to find inverse roots: use a look-up table.
    you only need a table of inverse roots for numbers m,
    1<m<=10.
    for a given x = 10^^E*m = 10^^(e/2) *10^^(E-e/2)*m, where e
    is the largest even integer less than or equal to E (if E is
    positive, e is the greatest even integer less than or equal to E,
    if E is negative), you need to look-up, at most, two inverse roots,
    perform one multiplication and one decimal shift:
    inverseRt(x) = 10^^(-e) * inverseRt(10) *inverseRt(m), if
    E-e/2 = 1 and
    inverseRt(x) = 10^^(-e) * inverseRt(m), if E-e/2 = 0.

Maybe you are looking for

  • I've installed firmware for my zen micro, now i can't use my creative software! Please he

    I wanted to download some music from napster and to play it on my player it told me I needed a firmware upgrade. I knew from buying my player that I probably would need to upgrade so I did. Once I installed the upgrade, and plugged my zen micro in an

  • About EP(on UNIX) UME integration with LDAP

    Hello guys, We want  that UME use LDAP(read-only) as data source  . Our EP installed on UNIX , LDAP on Windows. Connection data Server Name:    sapsso Server Port:      389 User:               p106658 (an administrator user) Password:        ****** U

  • [iPhone] Making a UIWebView scrollable from within a UIScrollView

    I'm building an app which consists of a UIScrollView which horizontally scrolls (much like the PageControl sample app), and which contains a UIWebView within each horizontally scrollable pane. Because of the fact that I'm using both of these objects,

  • Max no of Qualified links

    Hi,           Is there any limit of maximum number of qualified links that a field of type Lookup[Qualified Flat] (multi-valued) can contain. Regards, Sandeep Reddy.

  • Moving Address Book to encrypted disk image

    How can I protect the privacy of the content within Address Book and iCal? Would moving those applications to an encrypted disk image be sufficient or are there other related files located elsewhere that I need to be concerned with? Also, what would